﻿
using System;
using UnityEngine;

public enum UI_TYPE 
{
    START,
    LOAD,
    GAME,
    GAME_OVER
}

public class UISystem:MonoBehaviour
{
    public static UISystem Instance;

    private void Awake()
    {
        if (Instance != null && Instance != this)
        {
            Destroy(gameObject);
            return;
        }
        Instance = this;
        //DontDestroyOnLoad(gameObject);
    }

    [SerializeField] private UIBase _startUI;
    [SerializeField] private UIBase _loadUI;
    [SerializeField] private UIBase _gameUI;
    [SerializeField] private UIBase _gameOverUI;
    

    private UIBase _currentUI;

    public UIBase Show(UI_TYPE uiType,Action onShow=null,Action onHide=null)
    {
        if (_currentUI != null) 
        {
            _currentUI.OnClose(onShow); 
        }
        switch (uiType)
        {
            case UI_TYPE.START:
                _currentUI = _startUI;
                break;
            case UI_TYPE.LOAD:
                _currentUI = _loadUI;
                break;
            case UI_TYPE.GAME:
                _currentUI = _gameUI;
                break;
            case UI_TYPE.GAME_OVER:
                _currentUI = _gameOverUI;
                break;
            default:
                break;
        }

        _currentUI.OnOpen(onHide);
        
        return _currentUI;
    }
}

